$(document).ready(function() {
	//-----------------Report by Counter party Starts Here----------------------//
	//$("#reload-bar").show();
	var checked = 'true';
	var productByCpJsonBarSeriesData = new Array();
	var productByCpJsonBarCategories = new Array();
	var productByCpJson = new Array();
	window.refreshPositionByCpReport = function(){
		$('.loaddiv').show();
		productByCpJson = [];
		productByCpJsonBarSeriesData = [];
		productByCpJsonBarCategories = [];
		$.getJSON(
				ezopsContextPath
						+ '/getReports/getpositionbycppiechart?refresh=true',
				function(data) {
					//console.log('productByCpJson---'+productByCpJson);
					for ( var i = 0, len = data.length; i < len; i++) {
						productByCpJsonBarCategories.push([data[i].partyId]);
						productByCpJsonBarSeriesData.push([parseInt(data[i].agreementTypeCount)]);
						productByCpJson.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
					}
					getPositionByCpReport(productByCpJson);
					$('.loaddiv').hide();
				});
};

			$.getJSON(
					ezopsContextPath
							+ '/getReports/getpositionbycppiechart',
					function(data) {

						for ( var i = 0, len = data.length; i < len; i++) {
							productByCpJsonBarCategories.push([data[i].partyId]);
							productByCpJsonBarSeriesData.push([parseInt(data[i].agreementTypeCount)]);
							productByCpJson.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
						}
						getPositionByCpReport(productByCpJson);
					});
	$('#poscp-chart-view1').on('click', function(event) {
		//console.log('checked'+checked);
		if(checked == 'true'){
			//console.log('Checked');
			$('#productByCounterParty1')
			.highcharts(
					{
						chart : {
							type : 'bar'
						},

						title : {
							text : ''
						},
						subtitle : {
							text : ''
						},

						xAxis : {
							categories : productByCpJsonBarCategories
						},
						credits : {
							enabled : false
						},
						series : [ {
							name : 'Positions',
							data : productByCpJsonBarSeriesData

						} ]
					});

			

			checked = 'false';
		}
		else{
			checked = 'true';
			getPositionByCpReport(productByCpJson);
		}
		
	});

//-----------------POsition by Counter party Starts Here -------------------------//
// get the procuduct by cp report from server and create report

function getPositionByCpReport(productByCpJson) {
						// Build the chart4
						//console.log('processed_json');
						//console.log(productByCpJson);
						$('#productByCounterParty1')
						.highcharts(
								{
									chart : {
										plotBackgroundColor : null,
										plotBorderWidth : null,
										plotShadow : false
									},
									title : {
										text : ''
									},
									tooltip : {
										pointFormat : 'Positions: <b>{point.percentage:.1f}%</b>'
									},
									plotOptions : {
										pie : {
											allowPointSelect : true,
											cursor : 'pointer',
											dataLabels : {
												enabled : false
											},
											showInLegend : true
										}
									},
									series : [ {
										type : 'pie',
										name : '',
										data : productByCpJson
									} ]
								});
						
						
												}
//-----------------Report by Counter party Ends Here----------------------//

//-----------------Position by Product Starts Here -------------------------//
var positionByProductChecked = 'true';
var positionByProductBarSeriesArr = new Array();
var positionByProductBarCategoriesArr = new Array();
var positionByProductArr = new Array();
window.refreshPositionByProductReport = function(){
	$('.loaddiv1').show();
	positionByProductArr = [];
	positionByProductBarSeriesArr = [];
	positionByProductBarCategoriesArr = [];
$.getJSON(
		ezopsContextPath + '/getReports/getpositionbyproductpiechart?refresh=true',
		function(data) {
			for ( var i = 0, len = data.length; i < len; i++) {
				positionByProductArr.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
				positionByProductBarSeriesArr.push([parseInt(data[i].agreementTypeCount)]);
				positionByProductBarCategoriesArr.push([ data[i].partyId]);
			}
			//console.log('Calling getPositionByProductReport....');
			getPositionByProductReport(positionByProductArr);
			$('.loaddiv1').hide();
		});
};

$.getJSON(
		ezopsContextPath + '/getReports/getpositionbyproductpiechart',
		function(data) {
			for ( var i = 0, len = data.length; i < len; i++) {
				positionByProductArr.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
				positionByProductBarSeriesArr.push([parseInt(data[i].agreementTypeCount)]);
				positionByProductBarCategoriesArr.push([ data[i].partyId]);
			}
			//console.log('Calling getPositionByProductReport....');
			getPositionByProductReport(positionByProductArr);
		});

$('#posprod-chart-view1').on('click', function() {
	if(positionByProductChecked == 'true'){
		//console.log('Checked');
		$('#productByAccountType')
		.highcharts(
				{
					chart : {
						plotBackgroundColor : null,
						plotBorderWidth : null,
						plotShadow : false
					},
					title : {
						text : ''
					},
					tooltip : {
						pointFormat : 'Quantity: <b>{point.percentage:.1f}%</b>'
					},
					plotOptions : {
						pie : {
							allowPointSelect : true,
							cursor : 'pointer',
							dataLabels : {
								enabled : false
							},
							showInLegend : true
						}
					},
					series : [ {
						type : 'pie',
						name : '',
						data : positionByProductArr
					} ]
				});

		positionByProductChecked = 'false';
	}
	else{
		positionByProductChecked = 'true';
		getPositionByProductReport(positionByProductArr);
	}
	
});

function getPositionByProductReport(positionByProductArr) {
	//console.log('Called getPositionByProductReport....');
	//console.log('Data Used####'+positionByProductArr);

						// Build the chart4
						//console.log('processed_json');
						//console.log(positionByProductArr);
						$('#productByAccountType')
						.highcharts(
								{
									chart : {
										type : 'bar'
									},

									title : {
										text : ''
									},
									subtitle : {
										text : ''
									},

									xAxis : {
										categories : positionByProductBarCategoriesArr
									},
									credits : {
										enabled : false
									},
									series : [ {
										name : 'Positions',
										data : positionByProductBarSeriesArr

									} ]
								});
											//});
						//console.log('Call finished');

}



//-----------------Position by Product Ends Here -------------------------//

//-----------------Position by Currency Starts Here -------------------------//
var positionByCurrChecked = 'true';
var positionByCurrBarSeriesArr = new Array();
var positionByCurrBarCategoriesArr = new Array();
var positionByCurrArr = new Array();
window.refreshPositionByCurrencyReport = function(){
	$('.loaddiv2').show();
	positionByCurrArr = [];
	positionByCurrBarSeriesArr = [];
	positionByCurrBarCategoriesArr = [];
	$.getJSON(
			ezopsContextPath
					+ '/getReports/getpositionbycurrencypiechart?refresh=true',
			function(data) {

				for ( var i = 0, len = data.length; i < len; i++) {
					positionByCurrArr.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
					positionByCurrBarSeriesArr.push([ parseInt(data[i].agreementTypeCount) ]);
					positionByCurrBarCategoriesArr.push([ data[i].partyId ]);
				}
				getPositionByCurrencyReport(positionByCurrArr);
				$('.loaddiv2').hide();
			});
};

$.getJSON(
		ezopsContextPath
				+ '/getReports/getpositionbycurrencypiechart',
		function(data) {

			for ( var i = 0, len = data.length; i < len; i++) {
				positionByCurrArr.push([ data[i].partyId,parseInt(data[i].agreementTypeCount) ]);
				positionByCurrBarSeriesArr.push([ parseInt(data[i].agreementTypeCount) ]);
				positionByCurrBarCategoriesArr.push([ data[i].partyId ]);
			}
			getPositionByCurrencyReport(positionByCurrArr);
		});

$('#poscurr-chart-view1').on('click', function() {
	if(positionByCurrChecked == 'true'){
		//console.log('Checked');
		//console.log('positionByCurrBarSeriesArr##'+positionByCurrBarSeriesArr);
		//console.log('positionByCurrBarCategoriesArr##'+positionByCurrBarCategoriesArr);
		$('#productByCurrency')
		.highcharts(
				{
					chart : {
						type : 'bar'
					},

					title : {
						text : ''
					},
					subtitle : {
						text : ''
					},

					xAxis : {
						categories : positionByCurrBarCategoriesArr
					},
					credits : {
						enabled : false
					},
					series : [ {
						name : 'Positions',
						data : positionByCurrBarSeriesArr
					} ]
				});
		

		
		positionByCurrChecked = 'false';
	}
	else{
		positionByCurrChecked = 'true';
		getPositionByCurrencyReport(positionByCurrArr);
	}
	
});

function getPositionByCurrencyReport(positionByCurrArr) {

						// Build the chart4
						//console.log('processed_json');
						//console.log(positionByCurrArr);
						$('#productByCurrency')
						.highcharts(
								{
									chart : {
										plotBackgroundColor : null,
										plotBorderWidth : null,
										plotShadow : false
									},
									title : {
										text : ''
									},
									tooltip : {
										pointFormat : 'Positions: <b>{point.percentage:.1f}%</b>'
									},
									plotOptions : {
										pie : {
											allowPointSelect : true,
											cursor : 'pointer',
											dataLabels : {
												enabled : false
											},
											showInLegend : true
										}
									},
									series : [ {
										type : 'pie',
										name : '',
										data : positionByCurrArr
									} ]
								});
						
						
						
											//});
}
});
// -------Position by Currency Ends Here-----------//
/*****************Position Reports charts Ends here*****************************/



$(document).ready(
		function() {
			var source = {
				dataType : "json",
				dataFields : [ {
					name : 'Product.Description',
					type : 'string'
				}, {
					name : 'Product.AccountingType',
					type : 'string'
				}, {
					name : 'PartyId',
					type : 'string'
				}, {
					name : 'SettleCurrency',
					type : 'string'
				}, {
					name : 'Quantity',
					type : 'string'
				}, {
					name : 'Product.Isin',
					type : 'string'
				}, {
					name : 'PositionType',
					type : 'string'
				}, {
					name : 'SettleCurrency',
					type : 'string'
				} ],
				url : ezopsContextPath
						+ '/getReports/parsecsvforpositioncharts'
			};
			var dataAdapter = new $.jqx.dataAdapter(source, {
				loadComplete : function() {
					//console.log(dataAdapter);
				}
			});
			var cellClass = function(row, dataField, cellText, rowData) {
				var cellValue = rowData[dataField];
				switch (dataField) {
				case "diffQuantity":
					if (cellValue > 100 || cellValue < 0) {
						return "minavg";
					}
					if (cellValue <= 100) {
						return "max";
					}
					return "max";

				case "diffMarketValue":
					if (cellValue > 100 || cellValue < 0) {
						return "minavg";
					}
					if (cellValue <= 100) {
						return "max";
					}
					return "min";
				}
			};
			// create jqxDataTable for Position by CP.
			$("#positioncounter1").jqxGrid({
				source : dataAdapter,
				altRows : true,
				width : '99%',
				height : '600',
				sortable : true,
				pageable : false,
				filterable : true,
				groupable : true,
				showstatusbar : true,
				statusbarheight : 50,
				showaggregates : true,
				columnsresize : true,
				columnsreorder : true,

				columns : [ {
					text : 'Product',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'Product.Description',/* pinned: true,*/
					width : '20%'
				}, {
					text : 'Counterparty',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'PartyId',
					width : '20%'
				}, {
					text : 'AccountingType',
					dataField : 'Product.AccountingType',
					columngroup : 'ProductDetails',
					cellsformat : 'c2',
					align : 'center',
					cellsAlign : 'center',
					width : '20%'
				}, {
					text : 'Quantity',
					columngroup : 'ProductDetails',
					dataField : 'Quantity',
					cellsformat : 'd',
					cellsAlign : 'center',
					align : 'center',
					width : '20%'
				}, {
					text : 'SettleCurrency',
					cellsAlign : 'center',
					align : 'center',
					dataField : 'SettleCurrency',
					width : '20%'
				} ]

			});

			// create jqxDataTable for Position by Account Type.
			$("#positioncounter2").jqxGrid({
				source : dataAdapter,
				altRows : true,
				width : '99%',
				height : '600',
				sortable : true,
				pageable : false,
				filterable : true,
				groupable : true,
				showstatusbar : true,
				statusbarheight : 50,
				showaggregates : true,
				columnsresize : true,
				columnsreorder : true,

				columns : [ {
					text : 'Product',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'Product.Description',/* pinned: true,*/
					width : '20%'
				}, {
					text : 'Counterparty',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'PartyId',
					width : '20%'
				}, {
					text : 'AccountingType',
					dataField : 'Product.AccountingType',
					columngroup : 'ProductDetails',
					cellsformat : 'c2',
					align : 'center',
					cellsAlign : 'center',
					width : '20%'
				}, {
					text : 'Quantity',
					columngroup : 'ProductDetails',
					dataField : 'Quantity',
					cellsformat : 'd',
					cellsAlign : 'center',
					align : 'center',
					width : '20%'
				}, {
					text : 'SettleCurrency',
					cellsAlign : 'center',
					align : 'center',
					dataField : 'SettleCurrency',
					width : '20%'
				} ]

			});

			// create jqxDataTable for Position by Currency.
			$("#positioncounter3").jqxGrid({
				source : dataAdapter,
				altRows : true,
				width : '99%',
				height : '600',
				sortable : true,
				pageable : false,
				filterable : true,
				groupable : true,
				showstatusbar : true,
				statusbarheight : 50,
				showaggregates : true,
				columnsresize : true,
				columnsreorder : true,

				columns : [ {
					text : 'Product',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'Product.Description',/* pinned: true,*/
					width : '20%'
				}, {
					text : 'Counterparty',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'PartyId',
					width : '20%'
				}, {
					text : 'AccountingType',
					dataField : 'Product.AccountingType',
					columngroup : 'ProductDetails',
					cellsformat : 'c2',
					align : 'center',
					cellsAlign : 'center',
					width : '20%'
				}, {
					text : 'Quantity',
					columngroup : 'ProductDetails',
					dataField : 'Quantity',
					cellsformat : 'd',
					cellsAlign : 'center',
					align : 'center',
					width : '20%'
				}, {
					text : 'SettleCurrency',
					cellsAlign : 'center',
					align : 'center',
					dataField : 'SettleCurrency',
					width : '20%'
				} ]

			});

			/* Final Report Projection Grid */
			$("#positioncounter2").jqxGrid({
				source : dataAdapter,
				altRows : true,
				width : '99%',
				height : '600',
				sortable : true,
				pageable : false,
				filterable : true,
				groupable : true,
				showstatusbar : true,
				statusbarheight : 50,
				showaggregates : true,
				columnsresize : true,
				columnsreorder : true,

				columns : [ {
					text : 'Product',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'Product.Description',/* pinned: true,*/
					width : '20%'
				}, {
					text : 'Counterparty',
					cellsAlign : 'center',
					columngroup : 'ProductDetails',
					align : 'center',
					dataField : 'PartyId',
					width : '20%'
				}, {
					text : 'AccountingType',
					dataField : 'Product.AccountingType',
					columngroup : 'ProductDetails',
					cellsformat : 'c2',
					align : 'center',
					cellsAlign : 'center',
					width : '20%'
				}, {
					text : 'Quantity',
					columngroup : 'ProductDetails',
					dataField : 'Quantity',
					cellsformat : 'd',
					cellsAlign : 'center',
					align : 'center',
					width : '20%'
				}, {
					text : 'SettleCurrency',
					cellsAlign : 'center',
					align : 'center',
					dataField : 'SettleCurrency',
					width : '20%'
				} ]

			});

			// create jqxDataTable for Position by Currency.
			/*  var source =
			{
			dataType: "json",
			dataFields: [
					{ name: 'tradeId', type: 'string' },
					{ name: 'parentClearerId', type: 'string' },
					{ name: 'productGroup', type: 'string' },
					{ name: 'underlyingProductDescription', type: 'string' },
					{ name: 'productDescription', type: 'string' },
					{ name: 'cashCurrency', type: 'string' },
					{ name: 'realSettlementDate', type: 'string' },
					{ name: 'cashAmount', type: 'string' }

			], 
			url: ezopsContextPath+'/getReports/getfinaldepotprojectiongrid'
			};
			var dataAdapter = new $.jqx.dataAdapter(source, {
			loadComplete: function () {
			   console.log(dataAdapter);
			}
			});
			var cellClass = function (row, dataField, cellText, rowData) {
			var cellValue = rowData[dataField];
			switch (dataField) {
			   case "diffQuantity":
			       if (cellValue >100 || cellValue < 0) {
			           return "minavg";                            
			       }
			       if (cellValue <= 100 ) {
			           return "max";
			       }                       
			       return "max";
			       
			   case "diffMarketValue":
			       if (cellValue >100 || cellValue < 0) {
			           return "minavg";                            
			       }
			       if (cellValue <= 100 ) {
			           return "max";
			       }                        
			       return "min";                    
			}
			};
				
			   $("#finalDepotProjection").jqxGrid(
			   {
			       source: dataAdapter,
			       altRows: true,
			       width: '99%',
			       height: '600',
			       sortable: true,
			       pageable:false,
			       filterable: true,
			       groupable: true,
			       showstatusbar: true,
			       statusbarheight: 50,
			       showaggregates: true,
			       columnsresize: true,
			       columnsreorder: true,

			       
			       columns: [
						{text:'Trade Id',dataField:'tradeId',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
						{text:'Parent Clearer Id',dataField:'parentClearerId',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
						{text:'Product Group',dataField:'productGroup',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
						{text:'Underlying Product Description',dataField:'underlyingProductDescription',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
						{text:'Product Description',dataField:'productDescription',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
						{text:'Cash Currency',dataField:'cashCurrency',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
						{text:'Real Settlement Date',dataField:'realSettlementDate',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
						{text:'Cash Amount',dataField:'cashAmount',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'}

			       ]
			       
			   });   */

			// Master Aggrement Final Grid
			var source = {
				dataType : "json",
				dataFields : [ {
					name : 'entityId',
					type : 'string'
				}, {
					name : 'valuationMarketPlace',
					type : 'string'
				}, {
					name : 'agreementType',
					type : 'string'
				}, {
					name : 'id',
					type : 'string'
				}, {
					name : 'partyId',
					type : 'string'
				}, {
					name : 'signedDate',
					type : 'string'
				}

				],
				url : ezopsContextPath
						+ '/getReports/getmasteraggrementfinalgrid'
			};
			var dataAdapter = new $.jqx.dataAdapter(source, {
				loadComplete : function() {
					//console.log(dataAdapter);
				}
			});
			var cellClass = function(row, dataField, cellText, rowData) {
				var cellValue = rowData[dataField];
				switch (dataField) {
				case "diffQuantity":
					if (cellValue > 100 || cellValue < 0) {
						return "minavg";
					}
					if (cellValue <= 100) {
						return "max";
					}
					return "max";

				case "diffMarketValue":
					if (cellValue > 100 || cellValue < 0) {
						return "minavg";
					}
					if (cellValue <= 100) {
						return "max";
					}
					return "min";
				}
			};

			/*  $("#masterAggrementFinal").jqxGrid(
			 {
			     source: dataAdapter,
			     altRows: true,
			     width: '99%',
			     height: '600',
			     sortable: true,
			     pageable:false,
			     filterable: true,
			     groupable: true,
			     showstatusbar: true,
			     statusbarheight: 50,
			     showaggregates: true,
			     columnsresize: true,
			     columnsreorder: true,

			     
			     columns: [
				{text:'EntityId',dataField:'entityId',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Valuation Market Place',dataField:'valuationMarketPlace',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Agreement Type',dataField:'agreementType',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Id',dataField:'id',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'PartyId',dataField:'partyId',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'},
				{text:'Signed Date',dataField:'signedDate',cellsAlign: 'center',columngroup: 'ProductDetails', align: 'center',  width: '100px'}
			     ]
			     
			 });   */

			/* Chart data for Master Agreement Report */
			var masterAgreementJsonBarSeriesData = new Array();
			var masterAgreementJsonBarCategories = new Array();
			var masterAgreementJson = new Array();
			$.getJSON(ezopsContextPath
					+ '/getReports/getmasteragreemengpiechart', function(data) {
				for ( var i = 0, len = data.length; i < len; i++) {
					masterAgreementJsonBarCategories.push([ data[i].partyId ]);
					masterAgreementJsonBarSeriesData
							.push([ parseInt(data[i].agreementTypeCount) ]);
					masterAgreementJson.push([ data[i].partyId,
							parseInt(data[i].agreementTypeCount) ]);
				}
				getPositionByCpReport(masterAgreementJson);
				$('.loaddiv').hide();
			});
			var masterReportChecked = 'true';
			$('#master-chart-view1').on('click', function(event) {
				if (masterReportChecked) {
					$('#masterAggrementFinalChart').highcharts({
						chart : {
							type : 'bar'
						},

						title : {
							text : ''
						},
						subtitle : {
							text : ''
						},

						xAxis : {
							categories : cashUpcomingBarCategories
						},
						credits : {
							enabled : false
						},
						series : [ {
							name : 'Cash Amount',
							data : cashUpcomingBarSeriesData

						} ]
					});
					masterReportChecked = 'false';
				} else {
					masterReportChecked = 'true';
					getPositionByCpReport(masterAgreementJson);
				}

			});
			function getPositionByCpReport(masterAgreementJson) {
				// Build the chart4
				//console.log('processed_json');
				//console.log(masterAgreementJson);
				$('#masterAggrementFinalChart').highcharts({
					chart : {
						plotBackgroundColor : null,
						plotBorderWidth : null,
						plotShadow : false
					},
					title : {
						text : ''
					},
					/* tooltip : {
						pointFormat : 'Quantity: <b>{point.percentage:.1f}%</b>'
					}, */
					plotOptions : {
						pie : {
							allowPointSelect : true,
							cursor : 'pointer',
							dataLabels : {
								enabled : false
							},
							showInLegend : true
						}
					},
					series : [ {
						type : 'pie',
						name : '',
						data : masterAgreementJson
					} ]
				});

			}
		});

$(document)
		.ready(
				function() {
					var source = {
						dataType : "csv",
						dataFields : [ {
							name : 'ezId',
							type : 'string'
						}, {
							name : 'cp',
							type : 'string'
						}, {
							name : 'secType',
							type : 'string'
						}, {
							name : 'cpId',
							type : 'string'
						}, {
							name : 'underlier',
							type : 'string'
						} ],
						url : 'assets/sampledata/Aging-Report.csv'
					};
					var dataAdapter = new $.jqx.dataAdapter(source, {
						loadComplete : function() {
							// data is loaded.
						}
					});
					var cellClass = function(row, dataField, cellText, rowData) {
						var cellValue = rowData[dataField];
						switch (dataField) {
						case "diffQuantity":
							if (cellValue > 100 || cellValue < 0) {
								return "minavg";
							}
							if (cellValue <= 100) {
								return "max";
							}
							return "max";

						case "diffMarketValue":
							if (cellValue > 100 || cellValue < 0) {
								return "minavg";
							}
							if (cellValue <= 100) {
								return "max";
							}
							return "min";
						}
					}
					// create jqxDataTable.
					$("#AgingReportGrid").jqxGrid({
						source : dataAdapter,
						altRows : true,
						width : '99%',
						height : '600',
						sortable : true,
						pageable : false,
						filterable : true,
						groupable : true,
						showstatusbar : true,
						statusbarheight : 50,
						showaggregates : true,
						columnsresize : true,
						columnsreorder : true,

						columns : [ {
							text : 'Investment ID',
							cellsAlign : 'center',
							columngroup : 'ProductDetails',
							align : 'center',
							dataField : 'ezId',/* pinned: true,*/
							width : '20%'
						}, {
							text : 'Counterparty',
							cellsAlign : 'center',
							columngroup : 'ProductDetails',
							align : 'center',
							dataField : 'cp',
							width : '20%'
						}, {
							text : 'Sec Type',
							dataField : 'secType',
							columngroup : 'ProductDetails',
							cellsformat : 'c2',
							align : 'center',
							cellsAlign : 'center',
							width : '20%'
						}, {
							text : 'Trade Date',
							columngroup : 'ProductDetails',
							dataField : 'cpId',
							cellsformat : 'd',
							cellsAlign : 'center',
							align : 'center',
							width : '20%'
						}, {
							text : 'Confirmed: Y/N',
							cellsAlign : 'center',
							align : 'center',
							dataField : 'underlier',
							width : '20%',
							aggregates : [ 'count' ]
						} ]

					});

					$(function() {
						var chart;
						$(document)
								.ready(
										function() {
											// Build the chart4
											$('#containerpie1')
													.highcharts(
															{
																chart : {
																	plotBackgroundColor : null,
																	plotBorderWidth : null,
																	plotShadow : false
																},
																title : {
																	text : ''
																},
																tooltip : {
																	pointFormat : '{series.name}: <b>{point.percentage:.1f}%</b>'
																},
																plotOptions : {
																	pie : {
																		allowPointSelect : true,
																		cursor : 'pointer',
																		dataLabels : {
																			enabled : false
																		},
																		showInLegend : true
																	}
																},
																series : [ {
																	type : 'pie',
																	name : 'Share',
																	data : [
																			[
																					'Confirmed  ',
																					417 ],
																			[
																					'UnConfirmed < T+2 ',
																					50 ],
																			[
																					'UnConfirmed: 2- 5 days',
																					45 ],
																			[
																					'UnConfirmed: 6-30 days',
																					12 ],
																			[
																					'UnConfirmed >30 days',
																					2 ]

																	]
																} ]
															});
										}());

					}());

				});
$(document)
		.ready(
				function() {

					var source = {
						dataType : "csv",
						dataFields : [ {
							name : 'TaskID',
							type : 'number'
						}, {
							name : 'ParentTaskID',
							type : 'number'
						}, {
							name : 'TaskName',
							type : 'string'
						}, {
							name : 'Signoff_Type',
							type : 'string'
						}, {
							name : 'STATUS_OF_FILES',
							type : 'string'
						}, {
							name : 'Task_User',
							type : 'string'
						}, {
							name : 'COMMENT',
							type : 'string'
						}, {
							name : 'DATA_AVAILABILITY',
							type : 'string'
						}, {
							name : 'Ezopsuseremail',
							type : 'string'
						}, {
							name : 'COMPLETION',
							type : 'string'
						}, {
							name : 'UserEmail_ID',
							type : 'string'
						}, {
							name : 'UserEmail',
							type : 'string'
						} ],
						hierarchy : {
							keyDataField : {
								name : 'TaskID'
							},
							parentDataField : {
								name : 'ParentTaskID'
							}
						},
						id : 'TaskID',
						url : 'assets/sampledata/Positionsrecon.csv'
					};
					var dataAdapter = new $.jqx.dataAdapter(source);
					// create Tree Grid
					$("#treeGrid").jqxTreeGrid({
						width : '99%',
						source : dataAdapter,
						pageable : false,
						editable : true,
						columnsResize : true,
						sortable : true,
						filterable : true,
						filterMode : 'advanced',
						ready : function() {
							// expand row with 'EmployeeKey = 2'
							$("#treeGrid").jqxTreeGrid('expandRow', 0);
						},

						columns : [
						/*{ text: 'Client', dataField: 'Client', minWidth: 100, width: '8%' },*/
						{
							text : ' ',
							dataField : 'TaskName',
							minWidth : 150,
							width : '20%'
						}, {
							text : '',
							dataField : 'Signoff_Type',
							minWidth : 100,
							width : '6%'
						},/**/
						{
							text : 'EZ ID',
							dataField : 'STATUS_OF_FILES',
							minWidth : 110,
							width : '10%'
						}, {
							text : 'Street ID',
							dataField : 'Task_User',
							cellsFormat : 'd',
							minWidth : 80,
							width : '8%'
						}, {
							text : 'CP',
							dataField : 'COMMENT',
							cellsFormat : 'd',
							minWidth : 150
						}, {
							text : 'Sec Type',
							dataField : 'DATA_AVAILABILITY',
							cellsFormat : 'd',
							minWidth : 120,
							width : '8%'
						}, {
							text : 'Quantity',
							dataField : 'Ezopsuseremail',
							cellsFormat : 'd',
							minWidth : 120,
							width : '10%'
						}, {
							text : 'Description',
							dataField : 'COMPLETION',
							cellsFormat : 'd',
							minWidth : 100,
							width : '10%'
						}, {
							text : ' Trade Dt',
							dataField : 'UserEmail_ID',
							cellsFormat : 'd',
							minWidth : 150,
							width : '15%'
						}, {
							text : ' Maturity Dt',
							dataField : 'UserEmail',
							cellsFormat : 'd',
							minWidth : 150,
							width : '15%'
						} ]
					});

					$(function() {
						var chart;
						$(document)
								.ready(
										function() {
											// Build the chart4
											$('#containerpie7')
													.highcharts(
															{
																chart : {
																	plotBackgroundColor : null,
																	plotBorderWidth : null,
																	plotShadow : false
																},
																title : {
																	text : ''
																},
																tooltip : {
																	pointFormat : '{series.name}: <b>{point.percentage:.1f}%</b>'
																},
																plotOptions : {
																	pie : {
																		allowPointSelect : true,
																		cursor : 'pointer',
																		dataLabels : {
																			enabled : false
																		},
																		showInLegend : true
																	}
																},
																series : [ {
																	type : 'pie',
																	name : '',
																	data : [
																			[
																					'Total Positions',
																					526 ],
																			[
																					'Unmapped Positions',
																					2 ],
																			[
																					'Pos. w Quantity breaks',
																					4 ] ]
																} ]
															});
										});

					}());

				});

$(document)
		.ready(
				function() {
					// prepare the data
					var source = {
						dataType : "csv",
						dataFields : [ {
							name : 'ezId',
							type : 'string'
						}, {
							name : 'cp',
							type : 'string'
						}, {
							name : 'secType',
							type : 'string'
						}, {
							name : 'cpId',
							type : 'string'
						}, {
							name : 'underlier',
							type : 'string'
						} ],
						url : 'assets/sampledata/TradeFailures.csv'
					};
					var dataAdapter = new $.jqx.dataAdapter(source, {
						loadComplete : function() {
							// data is loaded.
						}
					});
					var cellClass = function(row, dataField, cellText, rowData) {
						var cellValue = rowData[dataField];
						switch (dataField) {
						case "diffQuantity":
							if (cellValue > 100 || cellValue < 0) {
								return "minavg";
							}
							if (cellValue <= 100) {
								return "max";
							}
							return "max";

						case "diffMarketValue":
							if (cellValue > 100 || cellValue < 0) {
								return "minavg";
							}
							if (cellValue <= 100) {
								return "max";
							}
							return "min";
						}
					}
					// create jqxDataTable.
					$("#TradeFailuresGrid").jqxGrid({
						source : dataAdapter,
						altRows : true,
						width : '99%',
						height : '600',
						sortable : true,
						pageable : false,
						filterable : true,
						groupable : true,
						showstatusbar : true,
						statusbarheight : 50,
						showaggregates : true,
						columnsresize : true,
						columnsreorder : true,

						columns : [ {
							text : 'Date',
							cellsAlign : 'center',
							columngroup : 'ProductDetails',
							align : 'center',
							dataField : 'ezId',/* pinned: true,*/
							width : '20%'
						}, {
							text : 'GS PB',
							cellsAlign : 'center',
							columngroup : 'ProductDetails',
							align : 'center',
							dataField : 'cp',
							width : '20%'
						}, {
							text : 'MS PB',
							dataField : 'secType',
							columngroup : 'ProductDetails',
							cellsformat : 'c2',
							align : 'center',
							cellsAlign : 'center',
							width : '20%'
						}, {
							text : 'Client',
							columngroup : 'ProductDetails',
							dataField : 'cpId',
							cellsformat : 'd',
							cellsAlign : 'center',
							align : 'center',
							width : '20%'
						}, {
							text : 'Failure Source',
							cellsAlign : 'center',
							align : 'center',
							dataField : 'underlier',
							width : '20%'
						} ]

					});

					$(function() {
						$('#containerpie6')
								.highcharts(
										{
											chart : {
												type : 'column'
											},
											title : {
												text : ''
											},
											subtitle : {
												text : ''
											},
											xAxis : {
												categories : [ '6-2-14',
														'6-3-14', '6-4-14',
														'6-6-14', '6-9-14' ]
											},
											yAxis : {
												min : 0,
												title : {
													text : ''
												}
											},
											tooltip : {
												headerFormat : '<span style="font-size:10px">{point.key}</span><table>',
												pointFormat : '<tr><td style="color:{series.color};padding:0">{series.name}: </td>'
														+ '<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
												footerFormat : '</table>',
												shared : true,
												useHTML : true
											},
											plotOptions : {
												column : {
													pointPadding : 0.2,
													borderWidth : 0
												}
											},
											series : [ {
												name : 'GS_PB',
												data : [ 1, 0, 1, 0, 1 ]

											}, {
												name : 'MS_PB',
												data : [ 2, 0, 0, 0, 0 ]

											}, {
												name : 'Client',
												data : [ 0, 1, 1, 2, 0 ]

											} ]
										});
					}());
				});
